package com.education.seckill.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.jwt.JWT;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.education.seckill.entity.SeckillGood;
import com.education.seckill.entity.SeckillOrder;
import com.education.seckill.mapper.SeckillOrderMapper;
import com.education.seckill.service.ISeckillGoodService;
import com.education.seckill.service.ISeckillOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.education.seckill.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Tang
 * @since 2022-06-20
 */
@Service
public class SeckillOrderServiceImpl extends ServiceImpl<SeckillOrderMapper, SeckillOrder> implements ISeckillOrderService {

    @Autowired
    private ISeckillGoodService seckillGood;

    @Autowired
    private RedisTemplate redisTemplate;
   /***
    *
    * 创建订单
    *
    * */
    @Override
    public  int createOrder( Long id) {
        SeckillGood good = seckillGood.getById(id);
        good.setSGoodStock(good.getSGoodStock()-1);
        seckillGood.updateById(good);

        SeckillOrder order = new SeckillOrder();
            order.setGoodsId(id);
            order.setPayStatus(0);
            this.save(order);
            return 1;
    }




}
